package mobi.greenplate.client.converter;

import mobi.greenplate.client.domain.Friend;

/**
 *
 * @author dmakariev
 */
public class FriendConverter {
    

    private FriendConverter() {
    }
    private static final String FRIEND_TAG="friend";
    private static final String ID = "id";
    private static final String USER_NAME = "userName";

    public static Friend endTag(Friend friend, String tagName, String text) {
        if (tagName.equalsIgnoreCase(ID)) {
            friend.setId(Long.valueOf(text));
        } else if (tagName.equalsIgnoreCase(USER_NAME)) {
            friend.setUserName(text);
        }
        return friend;
    }

    public static String toXml(Friend friend){
        final XmlBuilder xmlBuilder = XmlBuilder.newRoot(FRIEND_TAG);
        appendToXmlBuilder(xmlBuilder, friend);
        return xmlBuilder.buildXml();
    }

    private static void appendToXmlBuilder(XmlBuilder builder, Friend friend) {
        if (null != friend.getId()) {
            builder.addTag(ID, String.valueOf(friend.getId()));
        }

        builder.addTag(USER_NAME, friend.getUserName());/*.
                addTag(LATITUDE, String.valueOf(address.getLatitude())).
                addTag(LONGTITUDE, String.valueOf(address.getLongtitude())).
                addTag(STATE, address.getState()).
                addTag(STREET, address.getStreet()).
                addTag(ZIP, address.getZip());*/
    }
}
